package com.tyqx.hashchainbackend.controller;

import com.tyqx.hashchainbackend.service.AuthService;
import com.tyqx.hashchainbean.module.Authorize;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/auth")
public class AuthController {

    @Resource
    private AuthService authService;


    @RequestMapping(value = "/grantee", method = RequestMethod.GET, produces = "application/json")
    @ResponseBody
    public String grantee(Authorize authorize) {
        String message = "";
        try {
            if (authService.grantee(authorize) > 0) {
                message = "success";
            } else {
                message = "error";
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return message;
    }

    @RequestMapping(value = "/updateAuth", method = RequestMethod.GET, produces = "application/json")
    @ResponseBody
    public String updateAuth(Integer recordId, String granteeId,String grantorId,Integer flag) {
        String message = "";
        try {
            if (authService.updateAuth(recordId,granteeId,grantorId,flag) > 0) {
                message = "success";
            } else {
                message = "error";
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return message;
    }




}
